package com.ge.demo.restfulws.client;

import com.ge.demo.restfulws.beans.Company;
import com.ge.demo.restfulws.beans.Deal;

public class ExampleClient {

	private static final String serviceURL = "http://localhost:8080/RestfulWS";
	static final RestfulClientTemplate client = new RestfulClientTemplate(serviceURL);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String dealId = "1";
		Deal deal = client.post("/deal/" + dealId, Deal.class);
		printObjectDetails(deal);
	}
	
	private static void printObjectDetails(Deal deal) {
		System.out.println("Deal Id: " + deal.getPreCloseId() + " ("
				+ deal.getPostCloseId() + ")");
		System.out.println("Deal name: " + deal.getDealName());
		System.out.println("Self: " + deal.getId().getHref());

		if (deal.getParticipants().isEmpty()) {
			System.out.println("No participants");
		} else {
			System.out.println("Num. of participants: "
					+ deal.getParticipants().size());
			for (Company p : deal.getParticipants()) {
				printObjectDetails(p);
			}
		}
	}

	private static void printObjectDetails(Company company) {
		System.out.println("Participant Id: " + company.getCompanyId());
		System.out.println("Participant name: " + company.getCompanyName());
		System.out.println("Self: " + company.getId().getHref());
	}

}
